home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
dm3_mst.zip
/
MSTRMIND.C
< prev
next >
Wrap
Text File
|
1990-04-06
|
40KB
|
1,274 lines
/* ************************************************************************* */
/* */
/* M A S T E R M I N D */
/* */
/* Sample Door */
/* */
/* by Michael W. Bayley (Mycroft RBBS) - March 1, 1988 */
/* */
/* ************************************************************************* */
/* ************************************************************************* */
/* PROGRAM HISTORY */
/* ************************************************************************* */
/* 03/01/88 Version 1.00 */
/* 04/06/90 Version 2.00 Upgrade to DMLIB 3.00 Alpha */
/* */
/* */
/* */
/* */
/* ************************************************************************* */
/* **************************** */
/* Linkage References */
/* **************************** */
#include <stdio.h> /* standard header file */
#include <stdlib.h> /* standard library interface */
#include <string.h> /* string functions */
#include <process.h> /* process functions */
#include "dmdata.h" /* doorware data structures */
/* **************************** */
/* Global Data Section */
/* **************************** */
/* Flags & States */
int games; /* number of games played */
int tscore; /* total score */
int score; /* current score */
int codes[2][8]; /* solution matrix */
int matches; /* correct matches */
int positions; /* correct positions */
int games; /* current game number */
int guess; /* current guess number */
/* Players File structure */
struct player_data
{
char name[32]; /* Players name */
long games; /* Number of games played */
long score; /* Total turns used */
char game_date[12]; /* Last date played */
long game_end; /* last time user played */
long day_time; /* time user played */
int day_games; /* games user played */
};
int plrec;
struct player_data player_info;
/* Buffers */
char cyan[15]; /* Cyan color string */
char white[15]; /* White color string */
char grey[15]; /* Grey color string */
char qbuff[81]; /* line input buffer */
char input_line[255]; /* file input buffer */
char color_code[9] = { "WROYGBVK" }; /* color codes */
char code_str[6]; /* solution code */
char last_str[6]; /* last players guess */
char guess_str[6]; /* players guess */
/* File Names & Titles */
char mbanner1[81] = {"Mycroft Mastermind Version 1.00"};
char mbanner2[81] = {" Mycroft Mastermind Version 1.00"};
/* **************************** */
/* Program Code Section */
/* **************************** */
/* **************************** */
/* Mastermind - Main */
/* **************************** */
/*
* This program assume a standard Mycroft command line
*
* MSTRMIND Local
* MSTRMIND node Door monitor system
* MSTRMIND node path RBBS RBBS 16.x system
* MSTRMIND node path QBBS Quick BBS system
* MSTRMIND node path PCBOARD PCBOARD system
* MSTRMIND node path WILDCAT Wildcat system
*/
main(argc ,argv)
int argc;
char *argv[];
{
FS rfd; /* help file access structure*/
int line; /* help line counter */
int flow; /* help flow control */
int abort; /* help abort flag */
int st; /* return code status */
int i, j; /* work variables */
int playing; /* game is active */
int not_done, not_done1; /* while controls */
/*
* Initialize
*/
dmtimer_open(); /* Hook the timer */
switch(argc) /* Process BBS login */
{
case 1: /* Local */
st = read_bbs_info(-1, "\0", "\0");
break;
case 2: /* Monitor */
st = read_bbs_info(atoi(argv[1]), "\0", "\0");
break;
case 4: /* BBS */
st = read_bbs_info(atoi(argv[1]), argv[2], argv[3]);
break;
default: /* Illegal */
report_error("Error - Illegal command line parameters.");
bye(1, 0);
break;
}
switch(st)
{
case 0: /* No error */
break;
case -1: /* Can't locate NODES.BBS */
report_error("Error - Can't open NODES.BBS.");
break;
case -2: /* Can't find node record */
report_error("Error - Can't read node record in NODES.BBS.");
break;
case -3: /* Can't identify comm port */
report_error("Error - Can't identify comm port in NODES.BBS.");
break;
case -4: /* Illegal number of parameters */
report_error("Error - Bad number of parameters in PORTS.BBS.\r\n");
break;
case -5: /* Illegal comm port id */
report_error("Error - Bad comm port ID parameter in PORTS.BBS.\r\n");
break;
case -6: /* Illegal comm port address */
report_error("Error - Bad comm port address parameter in PORTS.BBS.\r\n");
break;
case -7: /* Illegal IRQ number */
report_error("Error - Bad IRQ number parameter in PORTS.BBS.\r\n");
break;
case -8: /* Illegal INT enable */
report_error("Error - Bad access type parameter in PORTS.BBS.\r\n");
break;
case -9: /* Illegal handshake */
report_error("Error - Bad handshake parameter in PORTS.BBS.\r\n");
break;
case -10: /* Illegal passthrough */
report_error("Error - Bad passthrough parameter in PORTS.BBS.\r\n");
break;
case -11: /* Duplicate comm port definition */
report_error("Error - Duplicate comm port definition in PORTS.BBS.\r\n");
break;
case -12: /* No defined port ids */
report_error("Error - No defined ports in PORTS.BBS.\r\n");
break;
case -13: /* Port not defined */
report_error("Error - Extended port not defined in PORTS.BBS.");
break;
case -21: /* Can't locate MESSAGES */
report_error("Error - Can't open MESSAGES.");
break;
case -22: /* Can't read node record */
report_error("Error - Can't read node record in MESSAGES.");
break;
case -23: /* Can't locate DORINFOx.DEF */
report_error("Error - Can't open DORINFOx.DEF.");
break;
case -24: /* Can't read DORINFOx.DEF */
report_error("Error - Can't read DORINFOx.DEF.");
break;
case -31: /* Can't locate PCBOARD.SYS */
report_error("Error - Can't open PCBOARD.SYS.");
break;
case -32: /* Can't read PCBOARD.SYS */
report_error("Error - Can't read PCBOARD.SYS.");
break;
case -41: /* Can't locate CALLINFO.BBS */
report_error("Error - Can't open CALLINFO.BBS.");
break;
case -42: /* Can't read CALLINFO.BBS */
report_error("Error - Can't read CALLINFO.BBS.");
break;
case -51: /* Can't locate DORINFOx.DEF */
report_error("Error - Can't open DORINFOx.DEF.");
break;
case -52: /* Can't read DORINFOx.DEF */
report_error("Error - Can't read DORINFOx.DEF.");
break;
case -61: /* Can't locate DOOR.SYS */
report_error("Error - Can't open DOOR.SYS.");
break;
case -62: /* Can't read DOOR.SYS */
report_error("Error - Can't read DOOR.SYS.");
break;
case -71: /* Can't locate CHAIN.TXT */
report_error("Error - Can't open CHAIN.TXT.");
break;
case -72: /* Can't read CHAIN.TXT */
report_error("Error - Can't read CHAIN.TXT.");
break;
case -81: /* Can't locate SFDOORS.DAT */
report_error("Error - Can't open SFDOORS.DAT.");
break;
case -82: /* Can't read DORINFOx.DEF */
report_error("Error - Can't read SFDOORS.DAT.");
break;
case -83: /* Can't locate SFMAIN.DAT */
report_error("Error - Can't open SFMAIN.DAT.");
break;
case -84: /* Can't read SFMAIN.DAT */
report_error("Error - Can't read SFMAIN.DAT.");
break;
case -85: /* Can't locate SFMESS.DAT */
report_error("Error - Can't open SFMESS.DAT.");
break;
case -86: /* Can't read SFMESS.DAT */
report_error("Error - Can't read SFMESS.DAT.");
break;
case -87: /* Can't locate SFFILE.DAT */
report_error("Error - Can't open SFFILE.DAT.");
break;
case -88: /* Can't read SFFILE.DAT */
report_error("Error - Can't read SFFILE.DAT.");
break;
case -101: /* Can't access TIMEOFFx.DOR */
report_error("Error - Can't access TIMEOFFx.DOR.");
break;
case -102: /* Can't access NAMES.DOR */
report_error("Error - Can't access NAMES.DOR.");
break;
case 1: /* Bad BBS type parameter */
report_error("Error - Unrecognized BBS type.");
break;
default: /* Unknown error */
sprintf(qbuff, "Error - Unrecognized return code [%d] from bbs_read_info().", st);
report_error(qbuff);
break;
}
if(st)
bye(1, 0);
/*
* Print Signon Screen
*/
print_string("Mycroft Mastermind\r\n");
print_string("Version 2.00 4/6/90\r\n");
print_string("by Michael W. Bayley\r\n");
print_string("Mycroft Systems BBS (408)927-0105\r\n");
print_string("\r\n");
sleep(2);
/*
* Force snoop on and no paging
*/
bbs_node_info.snoop[0] = ' ';
bbs_node_info.snoop[1] = '1';
bbs_node_info.sysop_avail[0] = ' ';
bbs_node_info.sysop_avail[1] = '0';
bbs_node_info.sysop_annoy[0] = ' ';
bbs_node_info.sysop_annoy[1] = '0';
/*
* Now welcome the player
*/
print_string(" Welcome, %s\r\n", user_name);
print_string(" to Mycroft Mastermind\r\n", user_name);
sleep(3);
/*
* Read in the player record from player file
*/
get_player_info();
/*
* Test time controls
*/
strcpy(user_game_date, player_info.game_date); /* Last date played */
user_game_end = player_info.game_end; /* last time user played */
user_day_time = player_info.day_time; /* time user played */
user_day_games = player_info.day_games; /* games user played */
st = time_controls("MSTRMIND.TIM");
switch(st)
{
case -3: /* Insufficient security for time window */
print_string("Error - Insufficient security for this time period.");
print_string(" Try again later.");
sleep(3);
bye(1, 0);
break;
case -2: /* Insufficient security */
print_string("Error - Insufficient security!");
print_string(" Check with SysOp.");
sleep(3);
bye(1, 0);
break;
case -1: /* Bad read of file */
report_error("Error - Reading time definitions.");
sleep(3);
break;
case 0: /* File is not being used */
break;
case 1: /* All is OK */
break;
}
st = daily_controls();
switch(st)
{
case -3: /* Exceeded daily time limit */
print_string("Error - You have you all of your daily time.");
print_string(" Try again tomorrow.");
sleep(3);
bye(1, 0);
break;
case -2: /* Exceeded daily entry limit */
print_string("Error - Daily run limit exceeded!");
print_string(" Try again tomorrow.");
sleep(3);
bye(1, 0);
break;
case -1: /* Isufficient wait */
report_error("Error - You must wait longer before you can");
print_string(" enter program, try later.");
sleep(3);
bye(1, 0);
break;
case 0: /* All is OK */
break;
}
player_info.day_time = user_day_time; /* time user played */
player_info.day_games = user_day_games; /* games user played */
/*
* Get User Selected Graphics Mode
*/
sleep(3); /* delay a while */
if(remote_user == 0)
{
/*
* If game is local, get graphics mode
*/
not_done = 1;
while(not_done)
{
print_string(" Enter your graphics mode (N=none, A=ASCII grpahics, G=ANSI graphics): ");
io_linput(input_line);
switch(input_line[0])
{
case 'N': /* No graphics */
case 'n':
user_graphics = 0;
not_done = 0;
break;
case 'A': /* No graphics */
case 'a':
user_graphics = 1;
not_done = 0;
break;
case 'G': /* No graphics */
case 'g':
user_graphics = 2;
not_done = 0;
break;
default: /* Bad Entry */
print_string(" Error - Bad response\r\n\r\n");
break;
}
}
}
/*
* Display Game Banner
*/
if(remote_user)
{
i = 0; /* Add player name to banner */
while((i < 18) && (user_name[i] != '\0'))
{
mbanner2[i] = user_name[i];
i++;
}
set_local_banner(mbanner2, WHITE, CYAN); /* Deluxe game banner */
}
else
set_local_banner(mbanner1, WHITE, CYAN); /* Standard game banner */
put_local_banner(); /* Show the banner */
/*
* Set up colors
*/
if(user_graphics == 2)
{
sprintf(cyan, "\033[1;36;40m"); /* Bright Cyan for color */
sprintf(white, "\033[1;37;40m"); /* Bright White for color */
sprintf(grey, "\033[0;37;40m"); /* Dim grey for standard */
}
else
{
sprintf(cyan, "\0"); /* No color use null string */
sprintf(white, "\0"); /* No color use null string */
sprintf(grey, "\0"); /* No color use null string */
}
/*
* Display Rules if Requested
*/
game_header();
print_string(white);
print_string(" Do you need instructions (Y/[N])? ");
print_string(grey);
io_linput(qbuff);
if(test_error(qbuff))
bye(1,0);
if(strcmp("Y", strupr(qbuff)) == 0)
{
switch(user_graphics)
{
case 0: /* No Graphics */
strcpy(rfd.name, "MSTRMIND.HPN");
break;
case 1: /* ASCII Graphics */
strcpy(rfd.name, "MSTRMIND.HPA");
break;
case 2: /* ANSIGraphics */
strcpy(rfd.name, "MSTRMIND.HPG");
break;
}
st = file_open(&rfd, FREAD, FBINARY, FNOCREATE);
if(st == 0)
{
line = 0;
flow = 1;
abort = 0;
/*
* Print help till aborted or done
*/
while((fgets(input_line, 255, rfd.fd) != 0) && (abort == 0))
{
if(flow)
i = print_metered(&line, input_line, qbuff);
else
{
i = print_string(input_line);
strcpy(qbuff, "\0");
}
switch(i) /* process results */
{
case 0: /* Normal operation */
break;
case 1: /* NS enetered */
flow = 0; /* turn off pausing */
break;
case 2: /* N enetered */
abort = 1; /* stop displaying */
break;
case -1: /* Unsure response */
if(test_error(qbuff)) /* abort if line problems */
{
file_close(&rfd); /* close the file */
bye(1,0); /* adios */
}
}
}
file_close(&rfd); /* close out the file */
}
else
report_error(" Error - Can't find rules file");
}
/*
* Wait for OK to start
*/
print_string(white);
print_string(" Press [ENTER] to begin...");
print_string(grey);
io_lxinput(qbuff);
if(test_error(qbuff))
bye(1,0);
backup(strlen(qbuff) + 53);
/*
* Note: The game employs color strings and cursor positioning.
*
* If the users graphics does not support this he will
* by default get grey text, and the game will scroll as
* it is played.
*
* If he does have ANSI capability he gets a single screen
* with color.
*/
/*
* Setup the game
*/
games = 0; /* no games completed */
tscore = 0; /* no score yet */
playing = 1; /* playing the game */
while(playing)
{
game_header(); /* redisplay game header */
games++; /* one more game */
score = 250; /* 200 points to start */
guess = 1; /* start with guess # 1 */
position_cursor(16, 8); /* Show game number */
print_string(white);
print_string("Game number: ");
print_string(grey);
print_string("%2d\r\n", games);
strcpy(last_str, "\0"); /* no last guess */
for(i = 0 ; i < 5 ; i++) /* pick the 5 digit code */
{
j = rand() & 0x07; /* entry is one of 8 colors */
code_str[i] = color_code[j]; /* select the letter */
}
code_str[5] = '\0'; /* null terminate */
/*
* The main game loop
*/
not_done = 1;
while(not_done)
{
/*
* Display play status
*/
position_cursor(45, 8); /* Show turn number */
print_string(white);
print_string("Guess number: ");
print_string(grey);
print_string("%2d\r\n", guess);
position_cursor(28, 11); /* Show last guess */
print_string(white);
print_string("Last guess was: ");
print_string(grey);
print_string(last_str);
print_string("\r\n");
/*
* Show prompt & get response
*/
position_cursor(28, 12); /* Get current guess */
print_string(white);
print_string("Current guess : ");
eol_display();
print_string(grey);
io_linput(qbuff);
/*
* Abort if remote error
*/
position_cursor(0, 22); /* Assume a message is comming */
if(test_error(qbuff))
{
games--;
if(games)
bye(0, (tscore * 10) / games);
else
bye(1, 0);
}
position_cursor(0, 22); /* Erase incase time warning */
eol_display();
print_string("\r\n");
/*
* Parse & Dispatch Command
*/
if(strcmp("QUIT", strupr(qbuff)) == 0) /* Quit command */
{
position_cursor(0, 22); /* set on communications line*/
print_string(white);
print_string("Sure you want to quit (Y/[N])? ");
print_string(grey);
io_linput(qbuff);
position_cursor(0, 22); /* Assume a message is comming */
if(test_error(qbuff))
{
games--;
if(games)
bye(0, (tscore * 10) / games);
else
bye(1, 0);
}
position_cursor(0, 22); /* Erase incase time warning */
eol_display();
if(strcmp("Y", strupr(qbuff)) == 0) /* Exit if YES */
{
games--;
if(games)
bye(0, (tscore * 10) / games);
else
bye(1, 0);
}
}
else if(strcmp("PAGE", strupr(qbuff)) == 0) /* Page command */
{
if(page_operator())
chat_mode();
else
{
position_cursor(0, 22);
print_string("Sorry, SysOp not available\r\n");
sleep(3);
position_cursor(0, 22);
eol_display();
}
}
else /* Assume a code was input */
{
if(strlen(qbuff) != 5)
{
/*
* Code must be 5 digits
*/
position_cursor(0, 22);
print_string(white);
print_string("Error - Bad number of code entries.\r\n");
sleep(5);
position_cursor(0, 22);
eol_display();
}
else
{
/*
* Guarantee upper case
*/
for(i = 0 ; i < 5 ; i++) /* Strip out bit 5 in each */
guess_str[i] = qbuff[i] & 0x5f;
guess_str[i] = '\0'; /* Null terminate the string */
/*
* Now count each color set
*/
for(i = 0 ; i < 8 ; i++) /* Init the solution matrix */
{
codes[0][i] = 0;
codes[1][i] = 0;
}
for(i = 0 ; i < 5 ; i++) /* do all five entries */
{
switch(code_str[i]) /* count the solution codes */
{
case 'W': /* White */
codes[0][0] += 1;
break;
case 'R': /* Red */
codes[0][1] += 1;
break;
case 'O': /* Orange */
codes[0][2] += 1;
break;
case 'Y': /* Yellow */
codes[0][3] += 1;
break;
case 'G': /* Green */
codes[0][4] += 1;
break;
case 'B': /* Blue */
codes[0][5] += 1;
break;
case 'V': /* Violet */
codes[0][6] += 1;
break;
case 'K': /* Black */
codes[0][7] += 1;
break;
}
switch(guess_str[i]) /* count the player codes */
{
case 'W': /* White */
codes[1][0] += 1;
break;
case 'R': /* Red */
codes[1][1] += 1;
break;
case 'O': /* Orange */
codes[1][2] += 1;
break;
case 'Y': /* Yellow */
codes[1][3] += 1;
break;
case 'G': /* Green */
codes[1][4] += 1;
break;
case 'B': /* Blue */
codes[1][5] += 1;
break;
case 'V': /* Violet */
codes[1][6] += 1;
break;
case 'K': /* Black */
codes[1][7] += 1;
break;
}
}
/*
* Now calculate matches
*/
matches = 0;
for(i = 0 ; i < 8 ; i++) /* for each color */
{
if(codes[0][i] >= codes[1][i])
matches += codes[1][i]; /* use player count */
else
matches += codes[0][i]; /* use solution count */
}
/*
* Now calculate positions
*/
positions = 0;
for(i = 0 ; i < 5 ; i++) /* for each code entry */
{
if(guess_str[i] == code_str[i]) /* if codes match */
positions++; /* one more correct pos. */
}
/*
* Update display to matches & positions
*/
position_cursor(16, 16); /* Show matches */
print_string(white);
print_string("Matched codes: ");
print_string(grey);
print_string("%d\r\n", matches);
position_cursor(45, 16); /* Show positions */
print_string(white);
print_string("Correct order: ");
print_string(grey);
print_string("%d\r\n", positions);
/*
* Test for final solution
*/
if(positions == 5)
{
/*
* Player has guessed the code
*/
position_cursor(0, 21); /* Let him know he won */
print_string(white);
print_string("Congratulations, you guessed the code.\r\n");
print_string("You have earned %d points for this game\r\n", score);
print_string(grey);
sleep(6);
position_cursor(0, 21);
eol_display();
position_cursor(0, 22);
eol_display();
/*
* Adjust his total score & check to play another game
*/
tscore += score;
not_done = 0;
position_cursor(0, 22);
print_string(white);
print_string("Play another (Y/[N]): ");
print_string(grey);
io_lxinput(qbuff);
if(test_error(qbuff))
bye(0, (tscore * 10) / games);
backup(strlen(qbuff) + 53);
if((qbuff[0] == 'Y') || (qbuff[0] == 'y'))
playing = 1;
else
playing = 0;
}
else
{
/*
* Bump the turn counter
* & remove possible points
*/
guess++;
strcpy(last_str, guess_str);
if(score > 0)
score -= 10;
}
}
}
}
}
/*
* Time to exit
*/
bye(0, (tscore * 10) / games);
}
/* **************************** */
/* Subroutine Section */
/* **************************** */
/* **************************** */
/* Game Header */
/* **************************** */
game_header()
{
cls_display();
print_string("\r\n");
switch(user_graphics)
{
case 0: /* No Grahics */
print_string("===============================================================================\r\n");
print_string("\r\n");
print_string(" M Y C R O F T M A S T E R M I N D \r\n");
print_string("\r\n");
print_string("===============================================================================\r\n");
break;
case 1: /* ASCII Grahics */
print_string("╔═════════════════════════════════════════════════════════════════════════════╗\r\n");
print_string("║ ║\r\n");
print_string("║ M Y C R O F T M A S T E R M I N D ║\r\n");
print_string("║ ║\r\n");
print_string("╚═════════════════════════════════════════════════════════════════════════════╝\r\n");
break;
case 2: /* ANSI Grahics */
print_string("\033[1;36;40m");
print_string("\033[1;36;40m╔═════════════════════════════════════════════════════════════════════════════╗\r\n");
print_string("\033[1;36;40m║ ║\r\n");
print_string("\033[1;36;40m║ \033[1;37;40mM Y C R O F T M A S T E R M I N D \033[1;36;40m║\r\n");
print_string("\033[1;36;40m║ ║\r\n");
print_string("\033[1;36;40m╚═════════════════════════════════════════════════════════════════════════════╝\r\n");
break;
}
print_string("\r\n");
print_string(grey);
return(0);
}
/* **************************** */
/* Test for Error Condition */
/* **************************** */
test_error(string)
char *string;
{
if(strcmp(string, "~NO_CARRIER") == 0)
{
print_string("ERROR - NO CARRIER, TERMINATING GAME!!!");
sleep(3);
return(-1);
}
if(strcmp(string, "~NOT_ACTIVE") == 0)
{
print_string("ERROR - NO TERMINAL ACTIVITY, TERMINATING GAME!!!");
sleep(3);
return(-1);
}
if(strcmp(string, "~TIME_WARNING") == 0)
{
print_string("WARNING - LESS THAN 5 MINUTES OF CONNECT TIME LEFT!!!");
sleep(3);
return(0);
}
if(strcmp(string, "~TIMEOUT") == 0)
{
print_string("ERROR - YOU HAVE USED ALL YOUR CONNECT TIME!!!");
sleep(3);
return(-1);
}
return(0);
}
/* **************************** */
/* Report Fatal Error */
/* **************************** */
report_error(string)
char *string;
{
FS efd;
int st;
/* Add error to end of file MSTRMIND.ERR */
strcpy(efd.name, "MSTRMIND.ERR");
st = file_open(&efd, FAPPEND, FTEXT, FCREATE);
if(st == 0)
{
fprintf(efd.fd, "%s\n", string);
file_close(&efd);
}
/* Also report error to virtual console */
print_string(string);
print_string("\r\n");
sleep(3);
return(0);
}
/* **************************** */
/* Return points to Monitor */
/* **************************** */
bye(flag, score)
int flag;
int score;
{
if(flag == 0)
{
/*
* Update player record and write it out
*/
put_player_info();
/*
* Show player his stats
*/
cls_display();
game_header();
print_string(white);
print_string("Todays totals\r\n");
print_string("-------------\r\n");
print_string("Total games : ");
print_string(grey);
print_string("%d\r\n", games);
print_string(white);
print_string("Total score : ");
print_string(grey);
print_string("%d\r\n", tscore);
print_string(white);
print_string("Average score: ");
print_string(grey);
print_string("%d\r\n", tscore / games);
print_string("\r\n");
if(remote_user)
{
print_string(white);
print_string("Overall totals\r\n");
print_string("--------------\r\n");
print_string("Total games : ");
print_string(grey);
print_string("%d\r\n", player_info.games);
print_string(white);
print_string("Total score : ");
print_string(grey);
print_string("%d\r\n", player_info.score);
print_string(white);
print_string("Average score: ");
print_string(grey);
print_string("%d\r\n", player_info.score / player_info.games);
}
if(mon_active)
{
print_string(white);
print_string("Door points: ");
print_string(grey);
print_string("%d\r\n", (tscore * 10) / games);
}
sleep(6);
}
print_string(grey);
print_string("\r\n");
print_string("\r\n");
print_string("\r\n");
io_close(); /* Release resources */
dmtimer_close();
mon_write(user_node, score); /* Exit via monitor if present */
mon_exit(user_node);
exit(flag);
}
/* **************************** */
/* Get player record */
/* **************************** */
get_player_info()
{
FS plfs;
int new_player;
int not_done;
/*
* Only if remote game.
*/
if(remote_user == 0)
return(0);
/*
* Open up the player file.
*/
new_player = 0;
strcpy(plfs.name, "MSTRMIND.DAT");
if(file_open(&plfs, FREAD, FBINARY, FNOCREATE))
new_player = 1;
else
{
/*
* Read it in
*/
plrec = 0;
new_player = 0;
not_done = 1;
while(not_done)
{
if(read(plfs.fh, &player_info, sizeof(struct player_data)) != sizeof(struct player_data))
{
new_player = 1;
not_done = 0;
}
else
{
if(strcmp(strupr(user_name), strupr(player_info.name)) == 0)
not_done = 0;
else
plrec++;
}
}
file_close(&plfs);
}
/*
* Init the structure if new player
*/
if(new_player)
{
strcpy(player_info.name, user_name); /* Players name */
player_info.games = 0L; /* Number of games played */
player_info.score = 0L; /* Total turns used */
strcpy(player_info.game_date, "Jan 01 1900"); /* Last date played */
player_info.game_end = 0L; /* last time user played */
player_info.day_time = 0L; /* time user played */
player_info.day_games = 0; /* games user played */
plrec = -1;
}
return(0);
}
/* **************************** */
/* Put player record */
/* **************************** */
put_player_info()
{
long lseek();
long cur_time();
FS plfs;
long ut;
char tbuf[12];
/*
* Only if remote game.
*/
if(remote_user == 0)
return(0);
/*
* Open up the player file.
*/
strcpy(plfs.name, "MSTRMIND.DAT");
if(file_open(&plfs, FAPPEND, FBINARY, FCREATE))
{
report_error("Error - Can't access player file.");
return(1);
}
else
{
/*
* Seek the record
*/
if(plrec != -1)
{
/* Go to players record */
if(lseek(plfs.fh, (long)(plrec) * sizeof(struct player_data), 0) == -1)
{
report_error("Error - Can't seek record.");
return(1);
}
}
/*
* Update the information
*/
player_info.games += games; /* Number of games played */
player_info.score += tscore; /* Total turns used */
get_date(player_info.game_date); /* Last date played */
player_info.game_end = cur_time(); /* last time user played */
if(player_info.game_end < user_signon)
ut = player_info.game_end + (24L * 60L * 60L);
else
ut = player_info.game_end;
player_info.day_time += ut - user_signon; /* time user played */
player_info.day_games++; /* games user played */
/*
* Write it out
*/
if(write(plfs.fh, &player_info, sizeof(struct player_data)) != sizeof(struct player_data))
{
report_error("Error - Can't write record.");
file_close(&plfs);
return(1);
}
file_close(&plfs);
}
/*
* Exit to caller
*/
return(0);
}